package itman.elm.controller;

import itman.elm.po.Business;
import itman.elm.service.BusinessService;
import itman.elm.service.impl.BusinessServiceImpl;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

public class BusinessController {

    public Object listBusinessByOrderTypeId(HttpServletRequest request, HttpServletResponse response) throws Exception{

        //1、先从Index.vue 组件中，获取orderTypeId
        //因为是String 类型，所以这里需要转成Integer类型
        Integer orderTypeId = Integer.valueOf(request.getParameter("orderTypeId"));

        //2、Controller 层看，调用Service层
        //所以此处获取了Service实例
        BusinessServiceImpl service = new BusinessServiceImpl();

        //3、调用listBusinessByOrderTypeId()传入我们的 orderTypeId
        // 主要是为了获取「所有的商家」，并将商家放入到 List 集合中，返回给调用者
        // 其实就是响应到客户端，然后客户端会循环遍历出所有商家，并呈现都页面
        List<Business> list = service.listBusinessByOrderTypeId(orderTypeId);

        return  list;
    }

public Object getBusinessById(HttpServletRequest request,HttpServletResponse response) throws Exception{

    Integer businessId = Integer.valueOf(request.getParameter("businessId"));

    BusinessService service = new BusinessServiceImpl();
    Business business = service.getBusinessById(businessId);

    return business;
}
}
